package com.maotouying.owlsmart.moviePage.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.maotouying.owlsmart.R;

import java.util.ArrayList;


public class list_A extends BaseAdapter implements ListAdapter {


        private ArrayList<list_C> list_cs;
        private int id;
        private Context context;
        private LayoutInflater inflater;

        public list_A(int item, Context context, ArrayList<list_C> list_cs) {
            this.list_cs = list_cs;
            this.context = context;
            this.id = item;
            inflater = LayoutInflater.from(context);

        }

        @Override
        public int getCount() {
            return list_cs.size();
        }

        @Override
        public Object getItem(int i) {
            return list_cs.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }


        @SuppressLint("WrongConstant")
        @Override

        public View getView(final int i, View view, ViewGroup viewGroup) {

           // vod_id,vod_name,vod_class,vod_year,vod_pic
            TextView vod_id = null;
            TextView vod_name = null;
            TextView vod_class = null;
            TextView vod_year = null;
            ImageView vod_pic = null;

            ViewHolder viewHolder;
            if (view == null) {
                view = inflater.inflate(id, null);

                vod_id = (TextView) view.findViewById(R.id.vod_id);
                vod_name = (TextView) view.findViewById(R.id.vod_name);
                vod_class = (TextView) view.findViewById(R.id.vod_class);
                vod_year = (TextView) view.findViewById(R.id.vod_year);
                vod_pic = (ImageView) view.findViewById(R.id.vod_pic);

                view.setTag(new ViewHolder(vod_id, vod_name, vod_class, vod_year, vod_pic));
            } else {
                ViewHolder viewHolder1 = (ViewHolder) view.getTag(); // 重新获取ViewHolder
                vod_id = viewHolder1.vod_id;
                vod_name = viewHolder1.vod_name;
                vod_class = viewHolder1.vod_class;
                vod_year = viewHolder1.vod_year;

                vod_pic = viewHolder1.vod_pic;

            }
            list_C lc = (list_C) list_cs.get(i); // 获取当前项的实例
            vod_id.setText(lc.getVod_id().toString());//对象为空
            vod_name.setText(lc.getVod_name().toString());
            vod_class.setText(lc.getVod_class().toString());
            vod_year.setText(lc.getVod_year().toString());


            //Glide设置图片圆角角度
            RoundedCorners roundedCorners = new RoundedCorners(10);
            //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
            // RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(20, 20);
            RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
            Glide.with(context)
                    .load(lc.getVod_pic().toString())
                    //.placeholder(R.drawable.ic_default_image)
                    .error(R.drawable.ic_vimage)
                    .apply(options)
                    .into(vod_pic);


            return view;

        }




        private final class ViewHolder {
            TextView vod_id = null;
            TextView vod_name = null;
            TextView vod_class = null;
            TextView vod_year = null;
            ImageView vod_pic = null;



            public ViewHolder(TextView vod_id,TextView vod_name,TextView vod_class,TextView vod_year,ImageView vod_pic) {
                this.vod_id = vod_id;
                this.vod_name = vod_name;
                this.vod_class = vod_class;
                this.vod_year = vod_year;
                this.vod_pic = vod_pic;


            }

        }
    }